package dom2;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;

public class ParseTwoXmlTest {

	public static void main(String argv[]) {

		parseXML();
		
		
	}

	public static void parseXML() {
		try {

			File file1 = new File("C:\\Users\\gya\\Desktop\\WebExport\\20130312_Kino_135909.xml");
			File file2 = new File("C:\\Users\\gya\\Desktop\\WebExport\\data.xml");
			
			
			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
			Document doc1 = dBuilder.parse(file1);
			Document doc2 = dBuilder.parse(file2);
			
			
			Element rootElement = doc1.getDocumentElement();
			rootElement.normalize();
			
			Node asset = doc2.getFirstChild();

			System.out.println("Root element :" + rootElement.getNodeName());

			NodeList nList = doc1.getElementsByTagName("VOS");

			System.out.println("----------------------------");

			for (int temp = 0; temp < nList.getLength(); temp++) {

				Node nNode = nList.item(temp);
				NodeList childNodes = nNode.getChildNodes();
				System.out.println("first childnode: " + childNodes.item(1).getNodeName());

				System.out.println("\nCurrent Element :" + nNode.getNodeName());

				if (nNode.getNodeType() == Node.ELEMENT_NODE) {

					Element eElement = (Element) nNode;

					System.out.println("TVSTATION : " + eElement.getElementsByTagName("TVSTATION").item(0).getTextContent());
					System.out.println("TITLE : " + eElement.getElementsByTagName("TITLE").item(0).getTextContent());
					System.out.println("SHOWNAME : " + eElement.getElementsByTagName("SHOWNAME").item(0).getTextContent());
					System.out.println("DESCRIPTION : " + eElement.getElementsByTagName("DESCRIPTION").item(0).getTextContent());
					System.out.println("DURATION : " + eElement.getElementsByTagName("DURATION").item(0).getTextContent());
					System.out.println("TIMEBASE : " + eElement.getElementsByTagName("TIMEBASE").item(0).getTextContent());
					System.out.println("ID : " + eElement.getElementsByTagName("ID").item(0).getTextContent());
					System.out.println("RUNDOWN : " + eElement.getElementsByTagName("RUNDOWN").item(0).getTextContent());
					System.out.println("RUNDOWNDATA : " + eElement.getElementsByTagName("RUNDOWNDATE").item(0).getTextContent());
					System.out.println("LANGUAGE : " + eElement.getElementsByTagName("LANGUAGE").item(0).getTextContent());
					System.out.println("TRANSMISSIONDATE : " + eElement.getElementsByTagName("TRANSMISSIONDATE").item(0).getTextContent());
					System.out.println("CREATIONDATE : " + eElement.getElementsByTagName("CREATIONDATE").item(0).getTextContent());
					System.out.println("EXPORTDATE : " + eElement.getElementsByTagName("EXPORTDATE").item(0).getTextContent());

				}
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}